#!/usr/bin/env perl
use warnings;
use strict;

use lib 'lib';

use Test::More tests => 5;
use_ok( 'Guile::Space' );

my @tests = (
    {   title   => 'simple method call',
        code    => q/ (object 'foo) /,
        scope   => { object => TestObj->new },
        result  => 23,
    },
    {   title   => 'object creating another object',
        code    => q/ ((object 'clone ) 'foo) /,
        scope   => { object => TestObj->new },
        result  => 23,
    },
    {   title   => 'isa check',
        code    => q/ (object 'isa "TestObj") /,
        scope   => { object => TestObj->new },
        result  => 1,
    },
    {   title   => 'method call with arguments',
        code    => q/ (object 'multiply 2 (object 'foo)) /,
        scope   => { object => TestObj->new },
        result  => 46,
    },
);

{   package TestObj;
    sub new         { bless {} }
    sub foo         { 23 }
    sub clone       { TestObj->new }
    sub multiply    { $_[1] * $_[2] }
}

my $space = Guile::Space->new;

for my $t (@tests) {

  SKIP: {
        if ( my $msg = $t->{skip} ) { skip $msg => 1 }
        is( $space->run( code => $t->{code}, scope => $t->{scope} ),
            $t->{result},
            $t->{title},
        );
    }
}



